package com.hee.erp.modules.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.hee.erp.common.R;
import com.hee.erp.modules.entity.Car;
import com.hee.erp.modules.entity.CarBrand;
import com.hee.erp.modules.entity.CarModel;
import com.hee.erp.modules.entity.SysLog;
import com.hee.erp.modules.service.*;
import com.hee.erp.vo.CarListParamsVo;
import com.hee.erp.vo.FiltersOption;
import com.hee.erp.vo.LogListParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/modules/car")
public class CarController {

    @Autowired
    ICarService carService;

    @Autowired
    ICarBrandService carBrandService;

    @Autowired
    ICarModelService carModelService;

    @Autowired
    ICarBuyingFilesService carBuyingFilesService;

    @Autowired
    ICarInsureWarnRuleService carInsureWarnRuleService;

    @Autowired
    ICarCheckWarnRuleService carCheckWarnRuleService;


    @PostMapping("/listByPage")
    @ApiOperation(value = "listByPage")
    public R<IPage<Car>> listByPage(@RequestBody CarListParamsVo params){
        IPage<Car> page = carService.listByPage(params);
        return R.success(page);
    }

    @ApiOperation(value = "getById")
    @GetMapping("/getById")
    public R<Car> getById(String id){
        Car entity = carService.getDetailById(id);
        return R.success(entity);
    }

    @PostMapping("/save")
    @ApiOperation(value = "save")
    public R<Car> save(@RequestBody Car entity){
        carService.saveDetail(entity);

        return R.success(entity);
    }

    @ApiOperation("delById")
    @GetMapping("/delById")
    public R<Boolean> delById(String id){
        carService.removeById(id);
        return R.success(true);
    }

    @GetMapping("/getFiltersOptions")
    @ApiOperation("getFiltersOptions")
    public R<List<FiltersOption>> getFiltersOptions(){
        List<FiltersOption> list = carService.getFiltersOptions();
        return R.success(list);
    }

    @GetMapping("/getCarBrandListAll")
    @ApiOperation("getCarBrandListAll")
    public R getCarTypeListAll(){
        List<CarBrand> list = carBrandService.list();
        return R.success(list);
    }

    @GetMapping("/getCarModelListByBrandId")
    @ApiOperation("getCarModelListByBrandId")
    public R getCarModelListByBrandId(String brandId){
        List<CarModel> list = carModelService.getListByBrandId(brandId);
        return R.success(list);
    }

    @GetMapping("/removeBuyingFilesById")
    @ApiOperation("removeBuyingFilesById")
    public R removeBuyingFilesById(String id){
        carBuyingFilesService.removeById(id);
        return R.success(true);
    }

    @GetMapping("/removeInsureWarnRuleById")
    public R removeInsureWarnRuleById(String id){
        carInsureWarnRuleService.removeById(id);
        return R.success(true);
    }

    @GetMapping("/removeCheckWarnRuleById")
    public R removeCheckWarnRuleById(String id){
        carCheckWarnRuleService.removeById(id);
        return R.success(true);
    }


}
